﻿using Furion;
using Furion.DependencyInjection;
using GWB.Application.SelectManage.Dtos;
using GWB.Application.System.OrgManage.OrgService;
using GWB.Core.TableEntity;
using GWB.Supplier;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GWB.Application.SelectManage.SelectService
{
    public class SelectService : SqlSugarDb, ITransient, ISelectService
    {
        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <returns></returns>
        public async Task<List<SelectOutDto>> GetRoleList()
        {
            var data = await RoleDal.GetListAsync();
            return data.Select(x => new SelectOutDto()
            {
                Value = x.Name,
                Key = x.Id
            }).ToList();
        }

        /// <summary>
        /// 获取组织树
        /// </summary>
        /// <returns></returns>
        public async Task<List<ParentSelectOutDto>> GetOrgTre()
        {
            var data = await App.GetService<IOrgService>().GetOrgTree();
            return Recursion(data);
        }

        /// <summary>
        /// 递归
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        private List<ParentSelectOutDto> Recursion(List<System.OrgManage.Dtos.OrgTreeOutDto> inputDto)
        {
            return inputDto.Select(x => new ParentSelectOutDto()
            {
                Children = Recursion(x.Children),
                ParentId = x.ParentId,
                Key = x.Key,
                Value = x.Title
            }).ToList();
        }

    }
}
